public class SearchPlansVF {

    public String planName {get; set;}
    public String status {get; set;}
    public String ownedBy {get; set;}
    public String eligibility {get; set;}
    public Plan__c p1StartDate = new Plan__c();
    public Plan__c p1EndDate = new Plan__c();
    public Plan__c[] planList {get; set;}
    
    public List<SelectOption> getPlanStatus()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('select', 'Select'));
        options.add(new SelectOption('Active', 'Active'));  
        options.add(new SelectOption('InActive', 'InActive'));
        
        return options; 
    }
    
/*    public List<SelectOption> getPlanEligibility()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('select', 'Select'));
        
        for(UserRole[] urList: [select Name from UserRole])
        {
            for(UserRole ur: urList)
            {
                options.add(new SelectOption(ur.Name, ur.Name));
                if(options.size() == 1000)
                    break;
            }
            if(options.size() == 1000)
                break;
        }
        return options; 
    } */
    
    public Plan__c getPlanStartDate()
    {
        return p1StartDate;
    }

    public Plan__c getPlanEndDate()
    {
        return p1EndDate;
    }
    
    public Plan__c[] getPlans()
    {
        return planList;    
    }
    
    public PageReference doSearch()
    {
        if(planName == '')
            planName = '%';
        else
            planName = '%'+planName+'%';

/*        Map<ID, String> pRoleMap = new Map<ID, String>();

        if(eligibility != 'select')
        {
            Plan_Role__c[] pRoles = [select Plan__c from Plan_Role__c where RoleTitle__c = :eligibility];        
                                
            for(Plan_Role__c pr : pRoles)
            {
                pRoleMap.put(pr.Plan__c, eligibility);        
            }      
            planList = [select Id, Name, Start_Date__c, End_Date__c, OwnerId, Plan__c.Owner.Name from Plan__c where Start_Date__c >= :p1StartDate.End_Date__c and End_Date__c <= :p1EndDate.End_Date__c and Id in :pRoleMap.keyset() and Name like :planName];
        }
        else */
            planList = [select Id, Name, Start_Date__c, End_Date__c, OwnerId, Plan__c.Owner.Name from Plan__c where Start_Date__c >= :p1StartDate.End_Date__c and End_Date__c <= :p1EndDate.End_Date__c and Name like :planName and Plan__c.Owner.Name like :'%'+ownedBy+'%'];
        if(planList.size() == 0)
            planList = null;  
        return null;
    }
    
    public PageReference inActive()
    {
        return null;
    }

    public PageReference newPlan()
    {
        PageReference p = new PageReference('/a00/e?retURL=%2Fa00%2Fo');
        p.setRedirect(true);
        return p;
    }
}